package guiCode;
import gui.CurrentCoursesIDGUI;
import gui.TeacherMainMenuGUI;
import gui.assignmentsGUI;
import java.sql.SQLException;

import javax.swing.JLabel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.JTableHeader;

import secretary.defineSemester;
import teacher.*;

import basic.ClientConsole;

import com.sun.rowset.CachedRowSetImpl;

import flexibility.CachedRowSetTableModel;
import flexibility.userData;

import com.sun.rowset.CachedRowSetImpl; 

public class CurrentCoursesIDcode {
	private assignmentsGUI asg;
	public userData T_Data = new userData();
	public TeacherMainMenuGUI tmm ;
	public ClientConsole teacherConnection=TeacherMainMenuCode.getTeacherConnection();
	public CachedRowSetImpl rs;
	int myID=TeacherMainMenuCode.getMyID();
	private CachedRowSetTableModel data;
	public defineSemester semester=new defineSemester();
	int currentSem;
	
	
	public CachedRowSetImpl getCoursesID(String s1){
		//s1=select course name
		getCoursesCurrSem gcc=new getCoursesCurrSem();
		currentSem=semester.identify(0, teacherConnection, rs);
		
		getCoursesID gc = new getCoursesID();
		rs=gc.getCourseID(teacherConnection, rs, T_Data, myID,s1,currentSem);
		
		return rs;	
	}
	
	public void update(CurrentCoursesIDGUI cc, CachedRowSetImpl crs) {
		JTableHeader tableHeader=new JTableHeader();
		
		
		try {
			cc.table.setModel(data = new CachedRowSetTableModel(crs));
			DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
			centerRenderer.setHorizontalAlignment(JLabel.CENTER);
			for (int i = 0; i < cc.table.getColumnCount(); i++)
				cc.table.getColumnModel().getColumn(i)
						.setCellRenderer(centerRenderer);
			cc.table.setEnabled(true);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	public void updateName(CurrentCoursesIDGUI cc,String s1){
		//s1=course name
		cc.setCourseName(s1);
	}

}
